/**
 *  @auth: sce
 *  @date: 17-12-29
 *  @desc: 菜单的reducer
 **/

import {
    MENU_INITIATE_REQUEST, MENU_RESOLVE_REQUEST, MENU_REJECT_REQUEST
} from './../action/menu'

export const menuReducer = (state = {
        hasMenu : false,
        isLoading : false,
        data : []
}, action) => {
    const {type} = action;
    switch (type) {
        case MENU_INITIATE_REQUEST:
            return {
                ...state,
                    hasMenu : false,
                    isLoading : true,
                    data : []
            };
        case MENU_RESOLVE_REQUEST:
            return {
                ...state,
                    hasMenu : true,
                    isLoading : false,
                    data : action.menuList
            };
        case MENU_REJECT_REQUEST:
            return {
                ...state,
                    hasMenu : false,
                    isLoading : false,
                    data : []
            };
        default:
            return state;
    }
};
